﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using SouthernLand.Common;
using SouthernLand.Common.BOL.NhaDat;

namespace SouthernLand.RaoVat
{
    public partial class Hethan : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Globals.CurrentUserID.Length < 5)
                Response.Redirect(Globals.ApplicationPath);

            if (Globals.GetStringFromQueryString("Action").ToLower() == "delete")
            {
                Raovat.Delete(Globals.GetIntFromQueryString("RaovatID"));
                Response.Redirect(Globals.ApplicationPath + "Raovat/HetHan.aspx");
            }

            lblTitle.Text = "TIN ĐÃ HẾT HẠN";

            Pager.IndexChanged += PageIndex_Changed;
            if (!Page.IsPostBack)
            {
                DataBind_Raovat();
            }
        }

        private void PageIndex_Changed(Object sender, EventArgs e)
        {
            DataBind_Raovat();
        }

        public void DataBind_Raovat()
        {
            // hien thi bao nhieu hinh tren 1 trang
            Pager.PageSize = 15;

            List<Raovat> obj = Raovat.GetRaovatHetHanByUser(Globals.CurrentUserID, Pager.PageIndex, Pager.PageSize);
            rptRaovat.DataSource = obj;
            rptRaovat.DataBind();

            int TotalRecords = 0;
            foreach (Raovat f in obj)
            {
                TotalRecords = f.TotalRecords;
                break;
            }

            if (TotalRecords <= 0)
            {
                PanelMsg.Visible = true;
                lblMsg.Text = "Bạn không có tin nào hết hạn.";
            }


            if (TotalRecords <= Pager.PageSize)
                DisplayPager.Visible = false;

            Pager.TotalRecords = CurrentPage.TotalRecords = TotalRecords;
            CurrentPage.TotalPages = Pager.CalculateTotalPages();
            CurrentPage.PageIndex = Pager.PageIndex;
        }
    }
}